package com.doit.day01

import scala.util.control.Breaks._

object _07_循环得中断 {
  def main(args: Array[String]): Unit = {

 /*   for(elem <- 1 to 10){
      //打印1 - 5 后面得就不打了
      if(elem <= 5){
        println(elem)
      }
    }*/

    //抛异常
/*    for(elem <- 1 to 10){
      println(elem)
      //打印1 - 5 后面得就不打了
      if(elem == 5){
        throw new Exception("不能打了，到5了")
      }
    }*/

/*    val breaks: Breaks = new Breaks()
    breaks.breakable(
      for(elem <- 1 to 10){
        println(elem)
        //打印1 - 5 后面得就不打了
        if(elem == 5){
          //中断
          breaks.break()
        }
      }
    )
    */
    //不用new Breaks 对象 也能够做，不过需要导包
    breakable(
      for(elem <- 1 to 10){
        println(elem)
        //打印1 - 5 后面得就不打了
        if(elem == 5){
          //中断
          break()
        }
      }
    )






  }
}
